package com.cyy.defstep;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.*;

import com.cyy.contanst.GlobalVar;
import io.cucumber.datatable.DataTable;
import io.cucumber.java.Scenario;
import io.cucumber.java.zh_cn.假如;
import io.cucumber.java.zh_cn.那么;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.text.StringSubstitutor;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Slf4j
public class CalDefstep {

    private int num1;
    private int num2;

    @假如("输入两个整数:{int}和{int}")
    public void input(int num1, int num2) {
        this.num1 = num1;
        this.num2 = num2;
    }

    @那么("两个数的和等于{int}")
    public void sum(int num) {
        assertThat(num1 + num2, equalTo(num));
    }

    @那么("^测试:(\\S+)$")
    public void test(String num) {

        StringSubstitutor stringSubstitutor = new StringSubstitutor(GlobalVar.value);
        String output = stringSubstitutor.replace(num);
        String stringLookup = stringSubstitutor.getStringLookup().toString();
        System.out.println(">>>> " + stringLookup);

    }

    /**
     * 正则匹配
     *
     * @param line    要匹配的字符串
     * @param pattern 正则表达式
     * @return 匹配的对象
     */
    public Matcher findAll(String line, String pattern) {
        Pattern r = Pattern.compile(pattern);
        Matcher matcher = r.matcher(line);
        return matcher;
    }

    @那么("打印表格数据")
    public void print_table(DataTable table) {
        log.info(table.asLists().toString());
    }

}
